<template>
	<view>
		<TX-PlayView 
		appId=1400249380
		appKey="e1262d907666861cefb431c67a859d9ac0cf369bd9126c4f337116e9571b8073"
		:roomId="roomId"
		:userId="userName"
		:role="role"
		:scene="scene"
		:enableLocalPreview="enable"
		:enableLocalAudio="enable"
		@statechange="onPush"
		ref="maxTxPlayView" 
		class="maxTxPlayView" 
		:style="{height:windowHeight}"></TX-PlayView>
	</view>
</template>

<script>
	const trtcCloud = uni.requireNativePlugin('TX-TRTCCloud');
	export default {
		data() {
			return {
				roomId: 868,
				windowHeight:0,
				role:20,
				userName:'xiaomei',
				scene:1,
				enable:false
			}
		},
		onLoad(params) {
		     // 获取上一个页面传入的参数
			this.role = params.role;
			this.windowHeight = uni.getSystemInfoSync().windowHeight;
			//设备的唯一标识
			this.userName = plus.device.uuid;
			
			
		},
		onReady() {
			
			var me = this;
			setTimeout(function () {
			    me.join();
			}, 200)
			
		},
		onNavigationBarButtonTap() {
			
			uni.navigateBack({
			    delta: 1,
			    animationType: 'pop-out',
			    animationDuration: 200
			});
		},
		
		onBackPress() {
			trtcCloud.exitRoom();
			trtcCloud.destroySharedIntance();
		},
		methods: {
			onPush(e){
				var result = e.detail;
				switch (result.type) {
					case 'onFirstVideoFrame':
						console.log('onFirstVideoFrame');
						break;
					case 'onUserEnter':
					    if(this.role == 21) {
							this.$refs.maxTxPlayView.startRemoteView(result.userId);
						}
					
						break;
				}
			},
			join(){
	            this.enable =  this.role == 20;
				this.$refs.maxTxPlayView.joinRoom();
			}
		}
	}
</script>

<style >

.maxTxPlayView{
	width:750upx;
	background-color:#111111;
	position: fixed;
	top: 0;
	right: 0;
}

</style>
